package com.migu.rbac.vo;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;

/**
 * 后台响应对象
 * @param <T>
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ResultResponseEntity<T> {
        private boolean isSuccess;
        private Integer errorCode;
        private String errorMsg;
        private List<T> list;
        private T entity;
        private Object body = "";

    public ResultResponseEntity() {
    }

    public ResultResponseEntity(ErrorCodes error) {
        this.isSuccess = false;
        this.errorCode = error.getCode();
        this.errorMsg = error.getDesc();
    }

    public static ResultResponseEntity req_ok(Object body) {
        ResultResponseEntity r = new ResultResponseEntity();
        r.setIsSuccess(true);
        r.setBody(body);
        return r;
    }

    public ResultResponseEntity(boolean isSuccess) {
        this.isSuccess = isSuccess;
    }


    public ResultResponseEntity(boolean isSuccess, T entity) {
        this.isSuccess = isSuccess;
        this.entity = entity;
    }

    public ResultResponseEntity(boolean isSuccess, List<T> list) {
        this.isSuccess = isSuccess;
        this.list = list;
    }

    public ResultResponseEntity(boolean isSuccess, String errorMsg) {
        this.isSuccess = isSuccess;
        this.errorMsg = errorMsg;
    }

    public ResultResponseEntity(boolean isSuccess, Integer errorCode, String errorMsg) {
        this.isSuccess = isSuccess;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public boolean getIsSuccess() {
            return isSuccess;
    }

    public void setIsSuccess(boolean isSuccess) {
            this.isSuccess = isSuccess;
    }

    public Integer getErrorCode() {
            return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
            this.errorCode = errorCode;
    }

    public String getErrorMsg() {
            return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
            this.errorMsg = errorMsg;
    }

    public List<T> getList() {
            return list;
    }

    public void setList(List<T> list) {
            this.list = list;
    }

    public T getEntity() {
            return entity;
    }

    public void setEntity(T entity) {
            this.entity = entity;
    }

    public Object getBody() {
        return body;
    }

    public void setBody(Object body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return "ResultResponseEntity{" +
                "isSuccess=" + isSuccess +
                ", errorCode=" + errorCode +
                ", errorMsg='" + errorMsg + '\'' +
                ", list=" + list +
                ", entity=" + entity +
                ", body=" + body +
                '}';
    }
}
